package com.example.mytransitiondemo.Transition;

import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Bundle;
import android.util.Pair;
import android.view.View;
import android.widget.Switch;

import com.example.mytransitiondemo.BaseActivity;
import com.example.mytransitiondemo.R;


public class TransitionActivity extends BaseActivity implements View.OnClickListener {

    private Intent mIntent = new Intent();
    private Switch isXml;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_transition);

        isXml = (Switch) findViewById(R.id.isXml);

        findViewById(R.id.explode).setOnClickListener(this);
        findViewById(R.id.slide).setOnClickListener(this);
        findViewById(R.id.fade).setOnClickListener(this);
        findViewById(R.id.share).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.explode:
                mIntent.setClass(this, TransitionToThisActivity.class);
                mIntent.putExtra("transition", "explode");
                mIntent.putExtra("isXml", isXml.isChecked());
                startActivity(mIntent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
                break;
            case R.id.slide:
                mIntent.setClass(this, TransitionToThisActivity.class);
                mIntent.putExtra("transition", "slide");
                mIntent.putExtra("isXml", isXml.isChecked());
                startActivity(mIntent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
                break;
            case R.id.fade:
                mIntent.setClass(this, TransitionToThisActivity.class);
                mIntent.putExtra("transition", "fade");
                mIntent.putExtra("isXml", isXml.isChecked());
                startActivity(mIntent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
                break;
            case R.id.share:
                mIntent.setClass(this, TransitionToThisActivity.class);
                mIntent.putExtra("transition", "share");
                ActivityOptions transitionActivityOptions = ActivityOptions.makeSceneTransitionAnimation(this
                        , Pair.create(findViewById(R.id.rectangle_red), "share")
                        , Pair.create(findViewById(R.id.share_text), "share_text"));
                //5.0以下兼容
//                ActivityOptionsCompat activityOptionsCompat1 = ActivityOptionsCompat.makeSceneTransitionAnimation(this
//                        , Pair.create(findViewById(R.id.rectangle_red), "share")
//                        , Pair.create(findViewById(R.id.share_text), "share_text"));
                startActivity(mIntent, transitionActivityOptions.toBundle());
                break;
        }
    }
}
